import controller.Record;
import repository.QueryDAO;
import repository.RecordDAO;
import util.InputUtil;

import java.sql.SQLException;

/**
 * @description:
 * @Author Felix Torn
 * @create: 2024-01-22 06:05
 **/

public class Main_cmd {
    public static void main(String[] args) {
        System.out.println("欢迎使用本系统~");
        do {
            System.out.println("请选择您要进行的操作：");
            System.out.println("1. 记录收入");
            System.out.println("2. 记录支出");
            System.out.println("3. 查询余额");
            System.out.println("4. 退出系统");
            System.out.print("请输入您的选择：");
            int choice = InputUtil.getInt();
            switch (choice) {
                case 1:
                    System.out.print("请输入收入金额：");
                    double incomeAmount = InputUtil.getDouble();
                    InputUtil.getString();
                    System.out.print("请输入收入来源：");
                    String incomeSource = InputUtil.getString();
                    System.out.print("请输入备注：");
                    String incomeNote = InputUtil.getString();
                    try {
                        if (Record.recordIncome(incomeAmount, incomeSource, incomeNote)) {
                            System.out.println("收入记录成功！");
                        } else {
                            System.out.println("收入记录失败！");
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    break;
                case 2:
                    System.out.print("请输入支出金额：");
                    double expenseAmount = InputUtil.getDouble();
                    InputUtil.getString();
                    System.out.print("请输入支出类别：");
                    String expenseCategory = InputUtil.getString();
                    System.out.println("请输入支出备注：");
                    String expenseNote = InputUtil.getString();
                    System.out.println("支出时间是否为当前时间：");
                    System.out.println("1. 是");
                    System.out.println("2. 否");
                    int timeChoice = InputUtil.getInt();
                    if (timeChoice == 2) {
                        System.out.println("请输入支出时间：");
                        System.out.print("年：");
                        int year = InputUtil.getInt();
                        System.out.print("月：");
                        int month = InputUtil.getInt();
                        System.out.print("日：");
                        int day = InputUtil.getInt();
                        System.out.print("时：");
                        int hour = InputUtil.getInt();
                        System.out.print("分：");
                        int minute = InputUtil.getInt();
//                        System.out.print("秒：");
                        int second = 0;
                        try {
                            if (Record.recordExpense(expenseAmount, expenseCategory,expenseNote, year, month, day, hour, minute, second)) {
                                System.out.println("支出记录成功！");
                            } else {
                                System.out.println("支出记录失败！");
                            }
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                        break;
                    }else {
                        try {
                            if (Record.recordExpense(expenseAmount, expenseCategory, expenseNote)) {
                                System.out.println("支出记录成功！");
                            } else {
                                System.out.println("支出记录失败！");
                            }
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                        break;
                    }
                case 3:
                    System.out.println("当前余额为：" + QueryDAO.getCurrentBalance() + "元");
                    break;
                case 4:
                    System.out.println("感谢您的使用，再见！");
                    System.exit(0);
                default:
                    System.out.println("输入有误，请重新输入！");
            }
        } while (true);
    }
}

